package com.toher.project.jasypt;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api")
@Slf4j
public class JasyptController {

    /**
     * 参数是字符串
     * @param text
     * @return
     */
    @RequestMapping("/param-text")
    @JasyptMethod
    public String isStringParam(String text){
        log.info("参数是字符串: {}" ,  text);
        return text;
    }

    /**
     * 参数是 单个对象
     * @param userDto
     * @return
     */
    @RequestMapping("/insert-user")
    @JasyptMethod
    public UserDto insertUser(@RequestBody UserDto userDto){
        log.info("参数是对象: {}" , userDto.toString());
        //TODO 操纵入库
        return userDto;
    }

    /**
     * 参数是 集合对象
     * @param userDtos
     * @return
     */
    @RequestMapping("/insert-users")
    @JasyptMethod
    public List<UserDto> insertUsers(@RequestBody List<UserDto> userDtos){
        log.info("参数是集合: {}", userDtos.toString());
        //TODO 操纵入库
        return userDtos;
    }


    /**
     * 返回是对象
     * @return
     */
    @RequestMapping("/get-user")
    @JasyptMethod("DEC")
    public UserDto getUser(){
        //模拟数据库取出
        UserDto userDto = new UserDto();
        userDto.setAge(10);
        userDto.setPhone("WyXyMRDDdvZEri1XcsPyMA/Pxv+f/N9ODU612IXi4HazSK5NicKK+zZJKolEz8bv");
        userDto.setIdCard("/KP3oTWB4pDRyyio54fJ+634pIS7VyVxltNACLG/gtDof4UDYTICMd+zsimbHGDJ0JwiubTLhHqMNxztyAU7zg==");
        return userDto;
    }

    /**
     * 返回是集合对象
     * @return
     */
    @RequestMapping("/get-users")
    @JasyptMethod("DEC")
    public List<UserDto> getUsers(){
        //模拟数据库取出
        UserDto userDto = new UserDto();
        userDto.setAge(10);
        userDto.setPhone("WyXyMRDDdvZEri1XcsPyMA/Pxv+f/N9ODU612IXi4HazSK5NicKK+zZJKolEz8bv");
        userDto.setIdCard("/KP3oTWB4pDRyyio54fJ+634pIS7VyVxltNACLG/gtDof4UDYTICMd+zsimbHGDJ0JwiubTLhHqMNxztyAU7zg==");

        UserDto userDto2 = new UserDto();
        userDto2.setAge(100);
        userDto2.setPhone("WyXyMRDDdvZEri1XcsPyMA/Pxv+f/N9ODU612IXi4HazSK5NicKK+zZJKolEz8bv");
        userDto2.setIdCard("/KP3oTWB4pDRyyio54fJ+634pIS7VyVxltNACLG/gtDof4UDYTICMd+zsimbHGDJ0JwiubTLhHqMNxztyAU7zg==");

        List<UserDto> userDtos = new ArrayList<>();
        userDtos.add(userDto);
        userDtos.add(userDto2);
        return userDtos;
    }
}
